﻿#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace TextGlow.Control.Model
{
  public class Text : RunContent
  {
    public const string LocalName = "t";

    private string _value;
    private bool _preserveSpace;

    public bool PreserveSpace
    {
      get { return _preserveSpace; }
      set { _preserveSpace = value; }
    }

    public string Value
    {
      get { return _value; }
      set { _value = value; }
    }

    public Text(Run parent, XElement element)
      : base(parent, element)
    {
      string textValue = element.Value;

      XNamespace xmlNs = XNamespace.Get("http://www.w3.org/XML/1998/namespace");
      string space = (string)element.Attribute(xmlNs + "space");

      // trim whitespace before and after text if spacing isn't being preserved
      if (string.CompareOrdinal(space, "preserve") != 0)
        textValue = textValue.Trim();

      _value = textValue;
    }

    public override RunContentType ContentType
    {
      get { return RunContentType.Text; }
    }

    public override string ToString()
    {
      return _value;
    }
  }
}